//
//  MainViewController.swift
//  Weibo19
//
//  Created by 城 on 15/11/8.
//  Copyright © 2015年 itcast. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    //中间加号点击事件
  @objc private func composeDidClick(){
        
        print(__FUNCTION__)
    }
    override func viewDidLoad() {
        super.viewDidLoad()
         //重写tabBar
        let mainBar = MainTabBar()
        //KVC赋值
        setValue(mainBar, forKey: "tabBar")
        //点击事件
        mainBar.composeBtn.addTarget(self, action: "composeDidClick", forControlEvents: .TouchUpInside)
   
        //添加控制器以及属性
        addChildViewController()
        
    }
    //添加tabBarController的子控制器
    private func addChildViewController() {
        addChildViewController(HomeTableViewController(), titleName: "首页", imageNmae: "tabbar_home")
        addChildViewController(MessageTableViewController(), titleName: "消息", imageNmae: "tabbar_message_center")
        addChildViewController(DiscoverTableViewController(), titleName: "发现", imageNmae: "tabbar_discover")
        addChildViewController(PriofileTableViewController(), titleName: "我", imageNmae: "tabbar_profile")
    }
    
    
//添加
    private func addChildViewController(childController: UIViewController,titleName:String,imageNmae:String) {
        //包navgitioncontroller
        let nav = UINavigationController(rootViewController: childController)
        //设置title
        childController.title = titleName
//设置普通图片
      childController.tabBarItem.image = UIImage(named: imageNmae)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)//让图片默认的颜色,,不被系统给渲染
   //设置点击的图片
      childController.tabBarItem.selectedImage = UIImage(named: "\(imageNmae)_highlighted")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
     //设置字体颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Selected)
        //添加navgitionController
        addChildViewController(nav)
    }

    
}
